<include file="Public/min-header" />
<div class="wrapper">
    <style type="text/css">
        .navbar{margin-bottom: 0px;}
        #fenlei_box{border: 1px solid #3297ff;position: absolute;width:380px;height:250px;overflow-y: auto; z-index:9999;background:#fff;display:none;margin-left: 38px;}
        #fenlei_box li{list-style: none;color:#3297ff;text-align:center;margin-left:-40px;line-height: 32px;cursor: pointer;padding-left:20px;padding-right:20px;}
    </style>
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <nav class="navbar navbar-default">
                            <div class="collapse navbar-collapse">
                                <form class="navbar-form form-inline"  method="get">
                                    <div class="form-group">添加：
                                        <input type="text" id="quyu" value="" class="input-sm" style="width: 380px;text-align: center;" oninput="quyu_sousuo($(this))" autocomplete="off" title="" placeholder="输入添加区域">
                                        <ul id="fenlei_box" rel="{$store.store_id}">
                                    </div>
                                </form>
                            </div>
                        </nav>
                    </div>
                    <div class="box-body">
                        <div class="row">
                            <div class="col-sm-12">
                                <table id="list-table" class="table table-bordered table-striped dataTable">
                                    <thead>
                                    <tr role="row">
                                        <th class="text-center">ID</th>
                                        <th class="text-center">区域名称</th>
                                        <th class="text-center">溢价比%</th>
                                        <th style="text-align: center;">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <foreach name="quyu_price" item="vo" key="k" >
                                        <tr class="text-center" role="row">
                                            <td class="text-center" style="padding:0;">{$vo.id}</td>
                                            <td class="text-center" style="padding:0;">{$vo.name}</td>
                                            <td class="text-center" style="padding:0;"><input type="text" rel="{$vo.id}" id="bianji" value="{$vo.hl}" style="width: 100px;"/>%</td>
                                            <td class="text-center" style="padding:0;">
                                                <a class="btn btn-danger" id="shanchu" rel="{$vo.id}">删除</a>
                                            </td>
                                        </tr>
                                    </foreach>
                                    </tbody>
                                    <tfoot>

                                    </tfoot>
                                </table>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-6 text-left">
                                <button class="btn btn-default btn-sm checkbox-toggle"><i class="fa fa-square-o"></i></button>
                            </div>
                            <div class="col-sm-6 text-right">{$page}</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <script type="text/javascript">
        $(document).ready(function() {

            $("body #bianji").change(function(){
                var myid=$(this).attr('rel'),myzhi=$(this).val();
                $.post('/Admin/Store/store_bianji_yijia_quyu/store_id/'+{:I('store_id')},
                {
                    action:'edit',
                        store_id:{:I('store_id')},
                    myid:myid,
                        zhi:myzhi,
                },
                function(data,status){
                    layer.msg('折扣编辑成功！',{icon:6});
                });
            });

            $("body").on("click", function() {
                $('body #fenlei_box').hide(100);
            });

            $("body #fenlei_box").on("click","li", function() {
                var ids=$(this).attr('rel'),text=$(this).attr('rev'),id=$(this).parent().attr('rel');
                ids=ids.split(',');
                $.post("/Admin/store/store_bianji_yijia_quyu",
                    {
                        action:'add',
                        store_id:id,
                        value:ids[ids.length-1]
                    },
                    function(data,status){
                        setTimeout(function(){
                            location.reload();
                        },1000);
                    });

            });

            $(".box-body #shanchu").click(function(){
                var del_id=$(this).attr('rel');
                $.post("/Admin/store/store_bianji_yijia_quyu",
                    {
                        action:'del',
                        store_id:{:I("store_id")},
                del_id:del_id
            },
                function(data,status){
                    location.reload();
                });
            });
        });

        function quyu_sousuo(obj)
        {
            var value = obj.val();
            $.ajax({
                url:"/Admin/store/quyu_sousuo?key="+value,
                success: function(data){
                    if(data!=''){
                        obj.parent().find('#fenlei_box').show(100);
                        obj.parent().find('#fenlei_box').html(data);
                    }else{
                        obj.parent().find('#fenlei_box').hide(100);
                    }
                }
            });
        }
    </script>
</div>
</body>
</html>
